﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.QixingManage;
using YiSha.Business.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Web.Code;
using YiSha.Util.Extension;
using YiSha.Model.Result.QixingManage;

namespace YiSha.Admin.Web.Areas.QixingManage.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-19 19:43
    /// 描 述：商品规格库存表控制器类
    /// </summary>
    [Area("QixingManage")]
    public class GoodsWarehouseController :  BaseController
    {
        private GoodsWarehouseBLL goodsWarehouseBLL = new GoodsWarehouseBLL();

        #region 视图功能
        [AuthorizeFilter("qixing:goodswarehouse:view")]
        public ActionResult GoodsWarehouseIndex()
        {
            return View();
        }

        public ActionResult GoodsWarehouseForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("qixing:goodswarehouse:search")]
        public async Task<ActionResult> GetListJson(GoodsWarehouseListParam param)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
                //if (param.shopid.IsNullOrZero())
                //{
                //    param.shopid = operatorInfo.shopid;
                //}
            }
            TData<List<GoodsWarehouseEntity>> obj = await goodsWarehouseBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:goodswarehouse:search")]
        public async Task<ActionResult> GetPageListJson(GoodsWarehouseListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
                //if (param.shopid.IsNullOrZero())
                //{
                //    param.shopid = operatorInfo.shopid;
                //}
            }
            TData<List<GoodsWarehouseEntity>> obj = await goodsWarehouseBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:goodswarehouse:search")]
        public ActionResult GetSelectCarListJson(GoodsWarehouseListParam param)
        {
            OperatorInfo operatorInfo =Operator.Instance.Current().Result;
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<goodscar>> obj =goodsWarehouseBLL.GetSelectCarListJson(param);
            return Json(obj);
        }
        

        [HttpGet]
        public async Task<ActionResult> GetFormJson(long id)
        {
            TData<GoodsWarehouseEntity> obj = await goodsWarehouseBLL.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("qixing:goodswarehouse:add,qixing:goodswarehouse:edit")]
        public async Task<ActionResult> SaveFormJson(GoodsWarehouseEntity entity)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                entity.tenant_id = operatorInfo.tenant_id;
            }
            TData<string> obj = await goodsWarehouseBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("qixing:goodswarehouse:delete")]
        public async Task<ActionResult> DeleteFormJson(string ids)
        {
            TData obj = await goodsWarehouseBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
